package com.quwan.manager.service.impl;

import com.quwan.common.enums.CommonStatus;
import com.quwan.common.query.LambdaQueryWrapperX;
import com.quwan.entity.TVipRule;
import com.quwan.manager.service.IVipRuleService;
import com.quwan.mapper.TVipRuleMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author laozhang
 * @date 2022/4/27 18:47
 */
@Service
@RequiredArgsConstructor
public class VipRuleServiceImpl implements IVipRuleService {
    @Autowired
    private TVipRuleMapper vipRuleMapper;

    @Override
    public List<TVipRule> getTVipRuleList() {
        LambdaQueryWrapperX<TVipRule> wrapper = new LambdaQueryWrapperX<TVipRule>()
                .eq(TVipRule::getStatus,CommonStatus.NORMAL.getType())
                .orderByDesc(TVipRule::getAddTime);
        return vipRuleMapper.selectList(wrapper);
    }

    @Override
    public boolean addTVipRule(TVipRule vipRule) {
        return vipRuleMapper.insert(vipRule.setStatus(CommonStatus.NORMAL.getType())) == 1;
    }

    @Override
    public boolean updateTVipRule(TVipRule vipRule) {
        return vipRuleMapper.updateById(vipRule) == 1;
    }

    @Override
    public TVipRule detailTVipRule(Integer id) {
        return vipRuleMapper.selectById(id);
    }

    @Override
    public boolean delTVipRule(Integer id) {
        return vipRuleMapper.updateById(new TVipRule().setId(id.longValue()).setStatus(CommonStatus.DISABLED.getType()))==1;
    }
}
